﻿using System;
using System.Collections.Generic;

using Lua = IronLua;
using Dlr = Microsoft.Scripting;
using AstFactory = Microsoft.Scripting.Ast.Ast;

namespace IronLua.Compiler {

	public class LuaCompiler : Lua.Ast.BaseAstVisitor {

		Dlr.Ast.CodeBlock block;

		public Dlr.Ast.CodeBlock CodeBlock {
			get { return block; }
		}

		public LuaCompiler (string name)
		{
			block = AstFactory.CodeBlock (name);
		}

		public static Dlr.Ast.CodeBlock Compile (Lua.Ast.BlockStatement block, string name)
		{
			var compiler = new LuaCompiler (name);
			block.Accept (compiler);
			return compiler.CodeBlock;
		}
	}
}
